package com.clz.latte.ec.sign;

import com.clz.latte.app.AccountManager;
import com.clz.latte.ec.database.DataBaseManager;
import com.clz.latte.ec.database.UserProfile;
import com.clz.latte.ec.entity.User;

/**
 * Created by Administrator on 2018/3/5.
 */

public class SignHandler {
    /**
     * 注册之后的操作
     * @param user
     * @param signListener
     */
    public static void onSignUp(User user,ISignListener signListener){
        final UserProfile userProfile = new UserProfile(user.getUserId(), user.getName(), user.getAvatar(),
                user.getGender(), user.getAddress());
        DataBaseManager.getInstance().getDao().insert(userProfile);
        //用户注册并登陆了
        AccountManager.setSignState(true);
        signListener.onSignUpSuccess();
    }
    /**
     * 登录之后的操作
     * @param user
     * @param signListener
     */
    public static void onSignIn(User user,ISignListener signListener){
        final UserProfile userProfile = new UserProfile(user.getUserId(), user.getName(), user.getAvatar(),
                user.getGender(), user.getAddress());
        DataBaseManager.getInstance().getDao().insert(userProfile);
        //用户登录了
        AccountManager.setSignState(true);
        signListener.onSignInSuccess();
    }
}
